// pages/projectDesription/projectDescription.js
var app = getApp();
const host = app.globalData.host;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    projectId: "",
    identity: "",
    candidateSchemeData:{
      status: "waiting"
    },
    selfInfo: {},
    workersAvatarUrls: [],
    projectInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log("options", options);
    that.setData({
      projectId: options.projectId,
      identity: app.globalData.userIdentity,
      selfInfo: app.globalData.userInfo
    });
    

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: host + 'city360/project/getProject',
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        projectId: that.data.projectId
      },
      complete: res => {
        console.log("查找到", res.data);
        that.setData({
          projectInfo: res.data
        })

        wx.request({
          url: host + 'city360/project/queryCandidateScheme',
          method: "POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            projectId: that.data.projectId
          },
          complete: res => {
            console.log(res);
            if (res.data === "wrong") {
              that.data.candidateSchemeData.status = "wrong"
              that.setData({
                candidateSchemeData: that.data.candidateSchemeData
              });
            } else {
              that.data.candidateSchemeData.status = "success";
              that.data.candidateSchemeData.src = host + res.data.imageFileName;
              that.setData({
                candidateSchemeData: that.data.candidateSchemeData
              });
            }
          }
        });

      }
    })

    //查找组员的头像
    wx.request({
      url: host + 'city360/project/queryWorkersAvatar',
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        projectId: that.data.projectId
      },
      complete: res => {
        that.data.workersAvatarUrls = res.data;
        console.log("avatars got", res.data);
        that.setData({
          workersAvatarUrls: that.data.workersAvatarUrls
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },


  yixiangfangan: function(event){
    app.globalData.newProjectDict.projectId = this.data.projectId
    wx.redirectTo({
      url: '../newProject/size/size',
    });
  },

  fangantoupiao: function(event){
    var that = this;
    wx.navigateTo({
      url: '../vote_candidate/vote_candidate?projectId=' + that.data.projectId,
    })
  },

  manageProject: function(event){
    console.log("点击了管理项目")
    var that = this;
    wx.navigateTo({
      url: '../manageProject/manageProject?projectId=' + that.data.projectId,
    });
  },

  zuizhongfangantoupiao: function(event){
    var that = this;
    wx.navigateTo({
      url: '../voteResult/voteResult?projectId=' + that.data.projectId,
    })
  }
})